package com.wx.router;

import java.util.HashMap;
import java.util.Map;

import com.wx.exception.WxException;
import com.wx.util.WxMpUtil;

import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;

public abstract class WxMpRouterProvider {

	private WxMpMessageRouterExt router;
	private String appName;
	private WxMpService wxMpService;
	private static Map<String, WxMpMessageRouter> routers = new HashMap<String, WxMpMessageRouter>();

	public WxMpRouterProvider(String appName) throws WxException {
		this.appName = appName;
		this.wxMpService = WxMpUtil.getWxMpServiceByAppName(appName);
		this.router = new WxMpMessageRouterExt(wxMpService);
	}

	public WxMpMessageRouter creater() throws WxException {
		configRule();
		return this.router;
	}

	private void configRule() {
		// try {
		// Class clzz = Class.forName("com.wx." + appName + ".AllRuleConfig");
		// Object allRuleConfig = clzz.newInstance();
		// // 根据构造函数来用
		//
		// WxMpMessageRouterRule tmpRule = null;
		// if (this instanceof MenuKey) {
		// Class ruleClzz =
		// Class.forName("com.wx.router.rule.event.MenuKeyRule");
		// tmpRule = this.router.rule(ruleClzz);
		// Method method = clzz.getMethod("", WxMpMessageRouter.class);
		// method.invoke(allRuleConfig, tmpRule);
		// // .end方法
		// }
		// } catch (ClassNotFoundException | SecurityException |
		// InstantiationException | IllegalAccessException
		// | IllegalArgumentException | NoSuchMethodException |
		// InvocationTargetException e) {
		// e.printStackTrace();
		// }
	}

}
